subroutine print_count_obj_header(lunit,ounit,myrank)
  use param
  use group_param,only:n_object_group
  use output_param,only:print_spatial_dist
  use count_param,only:spatial_file_name
  use box_param,only:channel_n
  use output_param,only:print_reaction_rate
  use output_param,only:prfn
  use group_param,only:n_react_group
  use table_param,only:n_sim_obj
  implicit none
  integer,intent(in) :: lunit,ounit,myrank
  integer :: i,j,nu,width
  character(len=len_linebuf) :: str

  nu=1000
  width=56

  do i=1,width
     str(i:i)='-'
  end do

  ! Print to the terminal
  if (myrank.eq.0) then
     write(*,*)
     write(*,'(a)') str(1:width)
     write(*,'(2x,"temp (K)",2x)',advance='no')
     write(*,'(2x,"time (s)",2x)',advance='no')
     write(*,'(4x,"dpa",5x)',advance='no')
     write(*,'(4x,"sdpa",4x)',advance='no')
     write(*,'(4x,"nobj")')
     write(*,'(a)') str(1:width)
  end if
  
  ! log file
  write(lunit,*)
  write(lunit,'(a)') str(1:width)
  write(lunit,'(2x,"temp (K)",2x)',advance='no')
  write(lunit,'(2x,"time (s)",2x)',advance='no')
  write(lunit,'(4x,"dpa",5x)',advance='no')
  write(lunit,'(4x,"sdpa",4x)',advance='no')
  write(lunit,'(4x,"nobj")')
  write(lunit,'(a)') str(1:width)

  ! output file
  write(ounit,*)
  write(ounit,'(4x,"temp",4x)',advance='no')
  write(ounit,'(4x,"time",4x)',advance='no')
  write(ounit,'(4x,"dpa",5x)',advance='no')
  write(ounit,'(4x,"sdpa",4x)',advance='no')
  do i=1,n_object_group
     write(ounit,'(i7,1x)',advance='no') i
  end do
  write(ounit,*)

  ! Spatial distribution
  if (print_spatial_dist) then
     do i=1,channel_n(1)
        open(unit=nu,file=spatial_file_name%fnx(i),&
             status='replace')
        write(nu,'(4x,"temp",4x)',advance='no')
        write(nu,'(4x,"time",4x)',advance='no')
        write(nu,'(4x,"dpa",5x)',advance='no')
        write(nu,'(4x,"sdpa",4x)',advance='no')
        do j=1,n_object_group
           write(nu,'(i7,1x)',advance='no') j
        end do
        write(nu,*)
        close(nu)
     end do
     do i=1,channel_n(2)
        open(unit=nu,file=spatial_file_name%fny(i),&
             status='replace')
        write(nu,'(4x,"temp",4x)',advance='no')
        write(nu,'(4x,"time",4x)',advance='no')
        write(nu,'(4x,"dpa",5x)',advance='no')
        write(nu,'(4x,"sdpa",4x)',advance='no')
        do j=1,n_object_group
           write(nu,'(i7,1x)',advance='no') j
        end do
        write(nu,*)
        close(nu)
     end do
     do i=1,channel_n(3)
        open(unit=nu,file=spatial_file_name%fnz(i),&
             status='replace')
        write(nu,'(4x,"temp",4x)',advance='no')
        write(nu,'(4x,"time",4x)',advance='no')
        write(nu,'(4x,"dpa",5x)',advance='no')
        write(nu,'(4x,"sdpa",4x)',advance='no')
        do j=1,n_object_group
           write(nu,'(i7,1x)',advance='no') j
        end do
        write(nu,*)
        close(nu)
     end do     
  end if

  if (print_reaction_rate) then
     open(unit=nu,file=prfn,status='replace')
        write(nu,'(4x,"temp",4x)',advance='no')
        write(nu,'(4x,"time",4x)',advance='no')
        write(nu,'(4x,"dpa",5x)',advance='no')
        write(nu,'(4x,"sdpa",4x)',advance='no')
        do j=1,n_react_group
           write(nu,'(4x,i4,4x)',advance='no') j
        end do
        write(nu,*)
     close(nu)
  end if

  return

end subroutine print_count_obj_header
